package com.baida.retail.tasksystem.dao.impl;

import com.baida.retail.tasksystem.dao.TaskDao;
import com.baida.retail.tasksystem.entity.Task;
import com.baida.retail.tasksystem.enums.TaskStatus;
import com.baida.retail.tasksystem.enums.TaskType;
import com.baida.retail.tasksystem.mapper.ext.TaskMapperExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class TaskDaoImpl implements TaskDao {
    @Autowired
    private TaskMapperExt taskMapperExt;

    @Override
    public int setTaskStatusToFinishedOnOrder(long orderId) {
        return taskMapperExt.updateTaskStatusToFinishedOnOrder(orderId);
    }

    @Override
    public Integer getMostUrgentTaskIdOwnedBy(int ownerId, TaskType taskType) {
        return taskMapperExt.selectMostUrgentTaskIdOwnedBy(ownerId, taskType.ordinal());
    }

    @Override
    public List<Task> getUnassignedTasks(int repoId, TaskType taskType) {
        return taskMapperExt.selectTasksByRepoIdAndStatus(repoId, TaskStatus.PENDING_ASSIGN.ordinal(), taskType.ordinal());
    }

    @Override
    public List<Task> getTasksByOrderId(long orderId) {
        return taskMapperExt.selectTasksByOrderId(orderId);
    }

    @Override
    public Task getTaskByOrderIdAndType(Long orderId, TaskType taskType) {
        return taskMapperExt.selectTask(orderId, taskType.ordinal());
    }

    @Override
    public List<Task> getUnfinishedTasks(int ownerId, TaskType taskType, int index, int size) {
        return taskMapperExt.selectUnfinishedTasks(ownerId, taskType.ordinal(), index, size);
    }

    @Override
    public List<Task> getFinishedTasks(int ownerId, TaskType taskType, int index, int size) {
        return taskMapperExt.selectFinishedTasks(ownerId, taskType.ordinal(), index, size);
    }

    @Override
    public int getUnfinishedTaskCount(int ownerId, TaskType taskType) {
        return taskMapperExt.getUnfinishedTaskCount(ownerId, taskType.ordinal());
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return taskMapperExt.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Task record) {
        return taskMapperExt.insert(record);
    }

    @Override
    public int insertSelective(Task record) {
        return taskMapperExt.insertSelective(record);
    }

    @Override
    public Task selectByPrimaryKey(Integer id) {
        return taskMapperExt.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Task record) {
        return taskMapperExt.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Task record) {
        return taskMapperExt.updateByPrimaryKey(record);
    }
}
